<?php
namespace App\Controller\Admin;

use App\Query\UserQuery;
use App\Query\UserLogQuery;
use App\Query\OrderQuery;

class TotalController extends Controller
{
    // 用户统计
    public function user()
    {
        // 时间条件
        $where = $this->inputs('time');
        
        // 基础方法
        $function = function () use($where)
        {
            return UserQuery::query(UserQuery::model(), $where);
        };
        
        return [
            'count' => $function()->count(),
            'money' => $function()->sum('money'),
            'money_make' => $function()->sum('money_make'),
            'money_shop' => $function()->sum('money_shop'),
            'money_point' => $function()->sum('money_point'),
            'money_other' => $function()->sum('money_other'),
            'money_wallet'=> $function()->sum('money_wallet'),
        ];
    }
    
    // 订单
    public function order()
    {
        // 时间条件
        $where = $this->inputs('time');
        
        // 基础方法
        $function = function () use($where)
        {
            return OrderQuery::statusPay(
                OrderQuery::query(OrderQuery::model(), $where)
            );
        };
        
        return [
            'count' => $function()->count(),
            'total' => $function()->sum('total'),
            'money' => $function()->sum('money'),
            'money_make' => $function()->sum('money_make'),
            'money_remain' => $function()->sum('money_remain'),
        ];
    }
    
    // 奖金
    public function userLog()
    {
        // 时间条件
        $where = $this->inputs('time', 'type');
        
        // 基础方法
        $function = function () use($where)
        {
            return UserLogQuery::query(UserLogQuery::model(), $where);
        };
        
        return [
            'money' => $function()->sum('money'),
        ];
    }
}
